<!DOCTYPE html>
<html>
<head>
<title>Circuit Diagram Fig 5.1</title>
</head>
<body>
<canvas id="circuitCanvas" width="800" height="450" style="border:1px solid #d3d3d3;"></canvas>
<script>
    const canvas = document.getElementById('circuitCanvas');
    const ctx = canvas.getContext('2d');

    // Helper function to draw a double-headed arrow
    function drawDoubleArrow(ctx, x, y1, y2) {
        const headlen = 10;
        ctx.beginPath();
        ctx.moveTo(x, y1);
        ctx.lineTo(x, y2);
        // Arrowhead at the top
        ctx.moveTo(x, y1);
        ctx.lineTo(x - headlen / 2, y1 + headlen);
        ctx.moveTo(x, y1);
        ctx.lineTo(x + headlen / 2, y1 + headlen);
        // Arrowhead at the bottom
        ctx.moveTo(x, y2);
        ctx.lineTo(x - headlen / 2, y2 - headlen);
        ctx.moveTo(x, y2);
        ctx.lineTo(x + headlen / 2, y2 - headlen);
        ctx.stroke();
    }

    // --- Start Drawing ---
    ctx.lineWidth = 1.5;
    ctx.strokeStyle = 'black';
    ctx.fillStyle = 'black';
    
    // Define main coordinates
    const yTop = 150;
    const yBottom = 350;
    const xInputTerminals = 100;
    const xMissingStart = 180;
    const xMissingEnd = 330;
    const xNode = 450;
    const xResistor = 650;
    const xOutputTerminals = 650;
    
    // --- Input Side ---
    // V_IN arrow and label
    drawDoubleArrow(ctx, 40, yTop, yBottom);
    ctx.font = "22px Arial";
    ctx.textAlign = 'left';
    ctx.textBaseline = 'middle';
    ctx.fillText("V", 55, 250);
    ctx.font = "16px Arial";
    ctx.fillText("IN", 68, 257);

    // Input terminals
    ctx.beginPath();
    ctx.arc(xInputTerminals, yTop, 5, 0, 2 * Math.PI);
    ctx.stroke();
    ctx.beginPath();
    ctx.arc(xInputTerminals, yBottom, 5, 0, 2 * Math.PI);
    ctx.stroke();

    // Wire from input to missing component
    ctx.beginPath();
    ctx.moveTo(xInputTerminals, yTop);
    ctx.lineTo(xMissingStart, yTop);
    ctx.stroke();

    // --- Missing Component ---
    // Dashed box
    ctx.save();
    ctx.setLineDash([6, 4]);
    ctx.strokeRect(xMissingStart, yTop - 20, xMissingEnd - xMissingStart, 40);
    ctx.restore();
    // Label and pointer
    ctx.font = "20px Arial";
    ctx.textAlign = 'center';
    ctx.fillText("missing component", (xMissingStart + xMissingEnd) / 2, yTop - 60);
    ctx.beginPath();
    ctx.moveTo((xMissingStart + xMissingEnd) / 2, yTop - 45);
    ctx.lineTo((xMissingStart + xMissingEnd) / 2, yTop - 20);
    ctx.stroke();

    // Wire from missing component to node
    ctx.beginPath();
    ctx.moveTo(xMissingEnd, yTop);
    ctx.lineTo(xNode, yTop);
    ctx.stroke();

    // --- Central parallel components ---
    // Nodes (junction points)
    ctx.beginPath();
    ctx.arc(xNode, yTop, 3, 0, 2 * Math.PI);
    ctx.fill();
    ctx.beginPath();
    ctx.arc(xNode, yBottom, 3, 0, 2 * Math.PI);
    ctx.fill();

    // Bottom wire
    ctx.beginPath();
    ctx.moveTo(xInputTerminals, yBottom);
    ctx.lineTo(xOutputTerminals, yBottom);
    ctx.stroke();

    // Capacitor (C)
    ctx.beginPath();
    ctx.moveTo(xNode, yTop);
    ctx.lineTo(xNode, yTop + 85);
    ctx.moveTo(xNode - 25, yTop + 85); // Top plate
    ctx.lineTo(xNode + 25, yTop + 85);
    ctx.moveTo(xNode - 25, yTop + 100); // Bottom plate
    ctx.lineTo(xNode + 25, yTop + 100);
    ctx.moveTo(xNode, yTop + 100);
    ctx.lineTo(xNode, yBottom);
    ctx.stroke();
    // Capacitor label
    ctx.font = "22px Arial";
    ctx.textAlign = 'right';
    ctx.fillText("C", xNode - 40, yTop + 92);

    // --- Output Side ---
    // Wires to output resistor
    ctx.beginPath();
    ctx.moveTo(xNode, yTop);
    ctx.lineTo(xResistor, yTop);
    ctx.moveTo(xNode, yBottom);
    ctx.lineTo(xResistor, yBottom);
    ctx.stroke();

    // Output terminals
    ctx.beginPath();
    ctx.arc(xOutputTerminals, yTop, 5, 0, 2 * Math.PI);
    ctx.stroke();
    ctx.beginPath();
    ctx.arc(xOutputTerminals, yBottom, 5, 0, 2 * Math.PI);
    ctx.stroke();

    // Resistor
    ctx.beginPath();
    ctx.moveTo(xResistor, yTop);
    ctx.lineTo(xResistor, yTop + 50);
    ctx.stroke();
    ctx.strokeRect(xResistor - 15, yTop + 50, 30, 100);
    ctx.beginPath();
    ctx.moveTo(xResistor, yTop + 150);
    ctx.lineTo(xResistor, yBottom);
    ctx.stroke();
    // Resistor label
    ctx.font = "20px Arial";
    ctx.textAlign = 'left';
    ctx.fillText("14 k\u03A9", xResistor + 25, 250);

    // V_OUT arrow and label
    drawDoubleArrow(ctx, 720, yTop, yBottom);
    ctx.font = "22px Arial";
    ctx.fillText("V", 735, 250);
    ctx.font = "16px Arial";
    ctx.fillText("OUT", 748, 257);

    // --- Figure Caption ---
    ctx.font = "20px Arial";
    ctx.textAlign = 'center';
    ctx.fillText("Fig. 5.1", canvas.width / 2, yBottom + 60);

</script>
</body>
</html>